package com.wxg.study.dao;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

public interface UserInfoRepository extends CrudRepository<UserInfo, Long> {

    public UserInfo findByUsername(String username);

    public UserInfo save(UserInfo userInfo);

    @Query(value="select uid, name, password, salt, state, username from user_info " +
            "where username = ?", nativeQuery=true)
    public UserInfo selByUsername(String username);

//    @Query(nativeQuery = true,
//            value = "INSERT into user_info (name, `password`, salt, state, username) " +
//            "VALUES(?, ?, ?, ?, ?)")
//    public UserInfo addUser(UserInfo userInfo);


    @Query(nativeQuery = true,
        value = "select uid, name, password, salt, state, username from user_info ORDER BY ?#{#pageable}",
        countQuery = "select count(1) from user_info")
    public Page<UserInfo> selAll(Pageable pageable);

}
